<html>
<head><meta charset="utf-8"><title>rental replacement · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html">rental replacement</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210338486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210338486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210338486">(Sep 17 2020 at 01:14)</a>:</h4>
<p>Are there any other replacements for the rental crate besides owning-ref?</p>



<a name="210338631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210338631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210338631">(Sep 17 2020 at 01:16)</a>:</h4>
<p>I feel like I've seen you ask this question before <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="210339055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339055">(Sep 17 2020 at 01:26)</a>:</h4>
<p>You mean seconds ago in Discord or longer in the past?</p>



<a name="210339082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339082">(Sep 17 2020 at 01:26)</a>:</h4>
<p>like a month or so ago</p>



<a name="210339085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339085">(Sep 17 2020 at 01:26)</a>:</h4>
<p>I've certainly asked it a while back.</p>



<a name="210339107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339107">(Sep 17 2020 at 01:27)</a>:</h4>
<p><strong>comex</strong>  and <strong>Josh Triplett</strong>  are going to make the compiler understand self-borrows, last I heard. <span aria-label="smirk" class="emoji emoji-1f60f" role="img" title="smirk">:smirk:</span></p>



<a name="210339151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339151">(Sep 17 2020 at 01:28)</a>:</h4>
<p>Now I'm thinking how to abuse futures / generators to do it.</p>



<a name="210339883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339883">(Sep 17 2020 at 01:42)</a>:</h4>
<p>I'm not aware of any bugs in rental, so even though it's not maintained I've been using it in my own project</p>



<a name="210339958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210339958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210339958">(Sep 17 2020 at 01:44)</a>:</h4>
<p>Oh, I will continue to use it as well. But people (reasonably) get skittish if I suggest that they use a project that has that big-ol "NOT MAINTAINED" banner.</p>



<a name="210352212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210352212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210352212">(Sep 17 2020 at 06:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/122651-general/topic/rental.20replacement/near/210339107">said</a>:</p>
<blockquote>
<p><strong>comex</strong>  and <strong>Josh Triplett</strong>  are going to make the compiler understand self-borrows, last I heard. <span aria-label="smirk" class="emoji emoji-1f60f" role="img" title="smirk">:smirk:</span></p>
</blockquote>
<p>I'm definitely not doing anything in this area. Some combination of Chalk and future type system improvements might help with self-borrows. <span class="user-mention" data-user-id="116009">@nikomatsakis</span> would know more than me; he gave a presentation mentioning it as a possibility.</p>



<a name="210416577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210416577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210416577">(Sep 17 2020 at 16:44)</a>:</h4>
<p>I thought it was polonious that made self-borrows a "more likely someday"</p>



<a name="210418239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/210418239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#210418239">(Sep 17 2020 at 16:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257428">Gus Wynn</span> <a href="#narrow/stream/122651-general/topic/rental.20replacement/near/210416577">said</a>:</p>
<blockquote>
<p>I thought it was polonious that made self-borrows a "more likely someday"</p>
</blockquote>
<p>Yep, that was it. Not Chalk :)</p>



<a name="211082220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211082220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211082220">(Sep 24 2020 at 01:50)</a>:</h4>
<p><a href="https://users.rust-lang.org/t/ouroboros-a-crate-for-making-self-referential-structs/49025">https://users.rust-lang.org/t/ouroboros-a-crate-for-making-self-referential-structs/49025</a></p>



<a name="211109476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211109476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211109476">(Sep 24 2020 at 09:49)</a>:</h4>
<p>The things that annoy me about most "self-referential" libraries out there, is that they (logically) use the tools currently at our disposal, which means using Rust references, usually <code>'static</code> references (since there is no other lifetime literal, such as <code>'none</code> / <code>'empty</code> / <code>'unsafe</code>). They also use built-in types such as <code>Box</code>.<br>
The issue is that both Rust reference types and things such as <code>Box</code> carry very heavy semantics &amp; invariants within the language, given how they are not <em>supposed</em> to be used within a self-referential struct.<br>
Easy improvements would be to replace things such as <code>Box</code> with a home-made <code>MyBox</code> wrapping a <code>ptr::NonNull</code> with <code>Deref{,Mut}</code> and <code>Drop</code>, so as to have effectively created an <code>AliasableBox</code>, but the <code>&amp;'static</code> references are a problem too.<br>
The true way to write these abstractions would require GAT, so a as to have <code>&amp;'lifetime T &lt;-&gt; Ref_&lt;T&gt;</code> mappings (the type on the right having no lifetime), and then have a <code>#[derive]</code> to recursively construct <code>Type&lt;'lifetime&gt;</code> into a lifetime-erased <code>Type_</code>. Then, and only then, using things like ouroboros APIs (which is a good start) would lead to 100% sound APIs / abstractions.</p>



<a name="211109587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211109587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211109587">(Sep 24 2020 at 09:50)</a>:</h4>
<p>Until then, manually constructed <code>Pin</code> types, and futures, or more generally, generators, and continuation-passing style (see <a href="https://docs.rs/with_locals">https://docs.rs/with_locals</a>) are the best things  at our disposal</p>



<a name="211122594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211122594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211122594">(Sep 24 2020 at 12:18)</a>:</h4>
<p>With locals looks interesting, but it infuriates me when docs don’t use rustfmt style.</p>



<a name="211196509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211196509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211196509">(Sep 24 2020 at 22:20)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> You could suggest in #rustdoc on Discord to add a docs example lint for formatting ;)</p>



<a name="211196785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211196785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211196785">(Sep 24 2020 at 22:22)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> those who care about such things can already do it. You can make your README in to a doc test and Rustfmt can check Rust code in markdown</p>



<a name="211198889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211198889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211198889">(Sep 24 2020 at 22:46)</a>:</h4>
<p>Rustdoc doesn't warn in tests by default though :/</p>



<a name="211199079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211199079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211199079">(Sep 24 2020 at 22:48)</a>:</h4>
<p>This is one of the reasons I wanted <code>--display-warnings</code>, <code>#[doc(test(attr(warn(warnings)))]</code> is not very discoverable</p>



<a name="211199350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211199350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211199350">(Sep 24 2020 at 22:52)</a>:</h4>
<p>oh wait this is about formatting, don't mind me</p>



<a name="211317626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211317626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211317626">(Sep 25 2020 at 21:02)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> </p>
<p>What about a custom attribute (not drive) which rewrites your self referencing structs to use ptr. offsets  instead of references and autogenerated the unsafe access code.</p>
<p>Through probably a bit tricky to get right without accidentally allowing something like "swap" to brake the safety constraints <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="211360591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rental%20replacement/near/211360591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rental.20replacement.html#211360591">(Sep 26 2020 at 13:40)</a>:</h4>
<p>It has been discussed on internals before. Here is a link I found: <a href="https://internals.rust-lang.org/t/internal-references-as-a-separate-type/12946">https://internals.rust-lang.org/t/internal-references-as-a-separate-type/12946</a><br>
One thing that approach can't help with is:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">A</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="n">text</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">   </span><span class="n">subText</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">text</span> <span class="kt">str</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>it somehow needs to know that <code>subText</code> should not change when <code>A</code> is moved, and that <code>A</code> can be moved even though <code>text</code> has a  borrow into it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>